Repository navigation
Include globals read only inside class bodies when pickling by value - #631
Open
draarivpatel-ui wants to merge 1 commit into
Open
draarivpatel-ui wants to merge 1 commit into
draarivpatel-ui wants to merge 1 commit into
Conversation
_extract_code_globals only collected names loaded with LOAD_GLOBAL, STORE_GLOBAL or DELETE_GLOBAL. Inside a class scope the compiler reads names with LOAD_NAME (class body statements and annotations before 3.14) and LOAD_FROM_DICT_OR_GLOBALS (class-scoped type aliases and the __annotate__ function on 3.14+), so a global referenced solely from a class body inside a by-value function was missing from the pickled globals and the depickled function raised NameError. Closes cloudpipe#609
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #609.
Problem
A global that a by-value function reads only inside the body of a class it defines was not included in the pickled globals, so the depickled function raised
NameError:Cause
_extract_code_globalsonly collects names loaded withLOAD_GLOBAL,STORE_GLOBALorDELETE_GLOBAL. Inside a class scope the compiler reads names with other opcodes:LOAD_NAME;typealias values (3.12+) and the class__annotate__function (3.14+) useLOAD_FROM_DICT_OR_GLOBALS.Fix
Add
LOAD_NAMEandLOAD_FROM_DICT_OR_GLOBALS(where available) toGLOBAL_OPS. Both consumers of_extract_code_globalsalready keep only names present infunc.__globals__, so class-local names collected this way are dropped, and names shadowed by the class body still resolve to the class-local value at runtime.Tests
Added
test_class_body_reads_globals(including the shadowing case) andtest_class_annotation_reads_globals. Full suite: 242 passed, 20 skipped, 2 xfailed.